package net.asfun.jvalog.resource;

import java.util.Collection;

import javax.jdo.Query;

import net.asfun.jvalog.common.Jdoer;
import net.asfun.jvalog.common.JdoerFactory;
import net.asfun.jvalog.entity.Sort;
import net.asfun.jvalog.vo.Pager;

public class SortDao {

	public static Collection<Sort> listAll() {
		return JdoerFactory.jdoSort.all();
	}

	public static Sort getBySlogan(String slogan) {
		Jdoer<Sort> jds = JdoerFactory.jdoSort;
		Query q = jds.prepareQuery();
		q.setFilter("slogan == slog");
		q.declareParameters("String slog");
		return jds.unique(q, slogan);
	}

	public static Collection<Sort> listAll(Pager pager) {
		Jdoer<Sort> jds = JdoerFactory.jdoSort;
		pager.setTotal(jds.all().size());
		Query q = jds.prepareQuery();
		q.setOrdering("order");
		q.setRange(pager.getStart(), pager.getEnd());
		return jds.more(q);
	}
}
